package edu.ihs.lhpy.action;

import java.util.List;

import javax.annotation.Resource;

import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Controller;

import com.opensymphony.xwork2.ActionContext;
import com.opensymphony.xwork2.ActionSupport;

import edu.ihs.lhpy.domain.*;
import edu.ihs.lhpy.service.BaseInfoService;
import edu.ihs.lhpy.service.InstituteService;
import edu.ihs.lhpy.service.NewsService;
import edu.ihs.lhpy.service.PrivilegeService;
import edu.ihs.lhpy.service.StudentsGuideService;
import edu.ihs.lhpy.service.TeacherService;
import edu.ihs.lhpy.service.UserService;
import edu.ihs.lhpy.service.WorkGuideService;
@Controller
@Scope("prototype")
public class IndexAction extends ActionSupport{
	
	@Resource
	protected TeacherService teacherService;
	@Resource
	protected InstituteService instituteService;
	@Resource
	protected UserService userService;
	@Resource
	protected PrivilegeService privilegeService;
	@Resource
	protected NewsService newsService;
	@Resource
	protected WorkGuideService workGuideService;
	@Resource
	protected StudentsGuideService studentsGuideService;
	@Resource
	protected BaseInfoService baseInfoService;
	
	private Long id;
	public Long getId() {
		return id;
	}
	public void setId(Long id) {
		this.id = id;
	}
	/**获取联合培养机构列表*/
	public void getInstitute(){
		List<Institute> instituteList = instituteService.findAll();
		ActionContext.getContext().put("instituteList", instituteList);
	}
	/**主页*/
	public String index() throws Exception {
		this.getInstitute();
		List<News> newsList = newsService.findIndexList();
		ActionContext.getContext().put("newsList", newsList);
		return "index";
	}
	/**培养方案*/
	public String trainPlan() throws Exception {
		//准备数据
		this.getInstitute();
		BaseInfo trainPlan= baseInfoService.getByType("trainPlan");
		ActionContext.getContext().getValueStack().push(trainPlan);
		return "trainPlan";
	}
	/**学位授予*/
	public String degreeGrant() throws Exception {
		this.getInstitute();
		BaseInfo degreeGrant= baseInfoService.getByType("degreeGrant");
		ActionContext.getContext().getValueStack().push(degreeGrant);
		return "degreeGrant";
	}
	/**工作流程*/
	public String workFlow() throws Exception {
		this.getInstitute();
		BaseInfo workFlow= baseInfoService.getByType("workFlow");
		ActionContext.getContext().getValueStack().push(workFlow);
		return "workFlow";
	}
	/**奖助体系*/
	public String award() throws Exception {
		this.getInstitute();
		BaseInfo award= baseInfoService.getByType("award");
		ActionContext.getContext().getValueStack().push(award);
		return "award";
	}
	/**招生简章列表*/
	
	public String studentsGuideList() throws Exception {
		this.getInstitute();
		PageBean pageBean = studentsGuideService.getPageBean(pageNum);
		ActionContext.getContext().getValueStack().push(pageBean);
		return "studentsGuideList";
	}
	/**招生简章*/
	public String studentsGuide() throws Exception{
		this.getInstitute();
		StudentsGuide studentsGuide = studentsGuideService.getById(id);
		ActionContext.getContext().getValueStack().push(studentsGuide);
		return "studentsGuide";
	}
	/**联系方式*/
	public String contact() throws Exception {
		
		this.getInstitute();
		BaseInfo contact= baseInfoService.getByType("contact");
		ActionContext.getContext().getValueStack().push(contact);
		return "contact";
	}
	/**办事指南列表*/
	public String workGuideList() throws Exception {
		
		this.getInstitute();
		PageBean pageBean = workGuideService.getPageBean(pageNum);
		ActionContext.getContext().getValueStack().push(pageBean);
		return "workGuideList";
	}
	/**办事指南*/
	public String workGuide() throws Exception{
		
		this.getInstitute();
		WorkGuide workguide = workGuideService.getById(id);
		ActionContext.getContext().getValueStack().push(workguide);
		return "workGuide";
	}
	/**新闻列表*/
	public String newsList() throws Exception {
		this.getInstitute();
		PageBean pageBean = newsService.getPageBean(pageNum);
		ActionContext.getContext().getValueStack().push(pageBean);
		return "newsList";
	}
	/**新闻*/
	public String news() throws Exception{
		
		this.getInstitute();
		News news = newsService.getById(id);
		ActionContext.getContext().getValueStack().push(news);
		return "news";
	}
	
	/**联合培养机构*/
	public String institute() throws Exception{
		
		this.getInstitute();
		Institute institute = instituteService.getById(id);
		ActionContext.getContext().getValueStack().push(institute);
		List<Teacher> teacherList = teacherService.getByInstitute(institute);
		ActionContext.getContext().put("teacherList", teacherList);
		return "institute";
	}
	
	/**联合培养机构*/
	public String teacher() throws Exception{
		
		this.getInstitute();
		Teacher teacher = teacherService.getById(id);
		ActionContext.getContext().getValueStack().push(teacher);
		return "teacher";
	}
	
	//第一页开始
	int pageNum = 1;
	public int getPageNum() {
		return pageNum;
	}
	public void setPageNum(int pageNum) {
		this.pageNum = pageNum;
	}
	
}
